home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '87 / Source ƒ.sea / Source ƒ / emacs source ƒ / BIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-11  |  14.8 KB  |  444 lines  |  [TEXT/MACA]

  1. /*    This file is for functions having to do with key bindings,
  2.     descriptions, help commands and startup file.
  3.  
  4.     written 11-feb-86 by Daniel Lawrence
  5.                                 */
  6.  
  7. #include    <stdio.h>
  8. #include    "estruct.h"
  9. #include    "edef.h"
  10. #include    "epath.h"
  11.  
  12. extern int meta(), cex(), unarg(), ctrlg(); /* dummy prefix binding functions */
  13.  
  14. deskey(f, n)    /* describe the command for a certain key */
  15.  
  16. {
  17.     register int c;        /* command character to describe */
  18.     register char *ptr;    /* string pointer to scan output strings */
  19.     register KEYTAB *ktp;    /* pointer into the command table */
  20.     register int found;    /* matched command flag */
  21.     register NBIND *nptr;    /* pointer into the name binding table */
  22.     char outseq[80];    /* output buffer for command sequence */
  23.  
  24.     /* prompt the user to type us a key to describe */
  25.     mlwrite(": describe-key ");
  26.  
  27.     /* get the command sequence to describe */
  28.     c = getckey(FALSE);            /* get a command sequence */
  29.  
  30.     /* change it to something we can print as well */
  31.     cmdstr(c, &outseq[0]);
  32.  
  33.     /* and dump it out */
  34.     ptr = &outseq[0];
  35.     while (*ptr)
  36.         (*term.t_putchar)(*ptr++);
  37.     (*term.t_putchar)(' ');        /* space it out */
  38.  
  39.     /* find the right ->function */
  40.     ktp = &keytab[0];
  41.     found = FALSE;
  42.     while (ktp->k_fp != NULL) {
  43.         if (ktp->k_code == c) {
  44.             found = TRUE;
  45.             break;
  46.         }
  47.         ++ktp;
  48.     }
  49.  
  50.     if (!found)
  51.         strcpy(outseq,"Not Bound");
  52.     else {
  53.         /* match it against the name binding table */
  54.         nptr = &names[0];
  55.         strcpy(outseq,"[Bad binding]");
  56.         while (nptr->n_func != NULL) {
  57.             if (nptr->n_func == ktp->k_fp) {
  58.                 strcpy(outseq, nptr->n_name);
  59.                 break;
  60.             }
  61.             ++nptr;
  62.         }
  63.     }
  64.  
  65.     /* output the command sequence */
  66.     ptr = &outseq[0];
  67.     while (*ptr)
  68.         (*term.t_putchar)(*ptr++);
  69. }
  70.  
  71. cmdstr(c, seq)    /* change a key command to a string we can print out */
  72.  
  73. int c;        /* sequence to translate */
  74. char *seq;    /* destination string for sequence */
  75.  
  76. {
  77.     char *ptr;    /* pointer into current position in sequence */
  78.  
  79.     ptr = seq;
  80.  
  81.     /* apply meta sequence if needed */
  82.     if (c & META) {
  83.         *ptr++ = 'M';
  84.         *ptr++ = '-';
  85.     }
  86.  
  87.     /* apply ^X sequence if needed */
  88.     if (c & CTLX) {
  89.         *ptr++ = '^';
  90.         *ptr++ = 'X';
  91.     }
  92.  
  93.     /* apply SPEC sequence if needed */
  94.     if (c & SPEC) {
  95.         *ptr++ = 'F';
  96.         *ptr++ = 'N';
  97.     }
  98.  
  99.     /* apply control sequence if needed */
  100.     if (c & CTRL) {
  101.         *ptr++ = '^';
  102.     }
  103.  
  104.     c = c & 255;    /* strip the prefixes */
  105.  
  106.     /* and output the final sequence */
  107.  
  108.     *ptr++ = c;
  109.     *ptr = 0;    /* terminate the string */
  110. }
  111.  
  112. help(f, n)    /* give me some help!!!!
  113.            bring up a fake buffer and read the help file
  114.            into it with view mode            */
  115. {
  116.     register int status;    /* status of I/O operations */
  117.     register WINDOW *wp;    /* scaning pointer to windows */
  118.     register BUFFER *bp;    /* buffer pointer to help */
  119.     register int i;        /* index into help file names */
  120.     char fname[NSTRING];    /* buffer to construct file name in */
  121.  
  122.     /* first check if we are already here */
  123.     bp = bfind("emacs.hlp", FALSE, BFINVS);
  124.  
  125.     if (bp == NULL) {
  126.         /* search through the list of help files */
  127.         for (i=2; i < NPNAMES; i++) {
  128.             strcpy(fname, pathname[i]);
  129.             strcat(fname, pathname[1]);
  130.             status = ffropen(fname);
  131.             if (status == FIOSUC)
  132.                 break;
  133.         }
  134.  
  135.         if (status == FIOFNF) {
  136.             mlwrite("[Help file is not online]");
  137.             return(FALSE);
  138.         }
  139.  
  140.         /* close the file to prepare for to read it in */
  141.         ffclose();
  142.     }
  143.  
  144.     /* split the current window to make room for the help stuff */
  145.     if (splitwind(FALSE, 1) == FALSE)
  146.             return(FALSE);
  147.  
  148.     if (bp == NULL) {
  149.         /* and read the stuff in */
  150.         if (getfile(fname, FALSE) == FALSE)
  151.             return(FALSE);
  152.     } else
  153.         swbuffer(bp);
  154.  
  155.     /* make this window in VIEW mode, update all mode lines */
  156.     curwp->w_bufp->b_mode |= MDVIEW;
  157.     curwp->w_bufp->b_flag |= BFINVS;
  158.     wp = wheadp;
  159.     while (wp != NULL) {
  160.         wp->w_flag |= WFMODE;
  161.         wp = wp->w_wndp;
  162.     }
  163.     return(TRUE);
  164. }
  165.  
  166. int (*fncmatch(fname))() /* match fname to a function in the names table
  167.                 and return any match or NULL if none        */
  168.  
  169. char *fname;    /* name to attempt to match */
  170.  
  171. {
  172.     register NBIND *ffp;    /* pointer to entry in name binding table */
  173.  
  174.     /* scan through the table, returning any match */
  175.     ffp = &names[0];
  176.     while (ffp->n_func != NULL) {
  177.         if (strcmp(fname, ffp->n_name) == 0)
  178.             return(ffp->n_func);
  179.         ++ffp;
  180.     }
  181.     return(NULL);
  182. }
  183.  
  184. /* bindtokey:    add a new key to the key binding table        */
  185.  
  186. bindtokey(f, n)
  187.  
  188. int f, n;    /* command arguments [IGNORED] */
  189.  
  190. {
  191.     register int c;        /* command key to bind */
  192.     register (*kfunc)();    /* ptr to the requexted function to bind to */
  193.     register char *ptr;    /* ptr to dump out input key string */
  194.     register KEYTAB *ktp;    /* pointer into the command table */
  195.     register int found;    /* matched command flag */
  196.     char outseq[80];    /* output buffer for keystroke sequence */
  197.     int (*getname())();
  198.  
  199.     /* prompt the user to type in a key to bind */
  200.     mlwrite(": bind-to-key ");
  201.  
  202.     /* get the function name to bind it to */
  203.     kfunc = getname();
  204.     if (kfunc == NULL) {
  205.         mlwrite("[No such function]");
  206.         return(FALSE);
  207.     }
  208.     (*term.t_putchar)(' ');        /* space it out */
  209.     (*term.t_flush)();
  210.  
  211.     /* get the command sequence to bind */
  212.     c = getckey((kfunc == meta) || (kfunc == cex) ||
  213.                 (kfunc == unarg) || (kfunc == ctrlg));
  214.  
  215.     /* change it to something we can print as well */
  216.     cmdstr(c, &outseq[0]);
  217.  
  218.     /* and dump it out */
  219.     ptr = &outseq[0];
  220.     while (*ptr)
  221.         (*term.t_putchar)(*ptr++);
  222.  
  223.     /* if the function is a prefix key */
  224.     if (kfunc == meta || kfunc == cex ||
  225.         kfunc == unarg || kfunc == ctrlg) {
  226.  
  227.         /* search for an existing binding for the prefix key */
  228.         ktp = &keytab[0];
  229.         found = FALSE;
  230.         whÈlk&aÁr>Aaõè`!r~í–K8˛iV*h6∑π    +ȘU™◊¥Ã}•Öo‹
  231. z⁄°gAäe@ˆØ+°§óŸhÖ·¬æòQe    õêsÄ◊{¶⁄≤v¿ „fl flÊǺJÌßüQ˙~ÊaßçÄÙ`¿®ÍÓıåk‰€√ÛP[ÔK£’≠d≈#x˝…ñ⁄?á‡Ñ|l∞\π”ñ î¥@?•ÉÁÜ´6M§ÙGΩz™…sœæ Ù.Ù™N˜E’]`=¥Õ•uÉÖ=§#sÁF ÊdÄ!˛Ó€∏ȖăE
  232. vüPf·OEÚ[Å˘„å±`ƒ_|ºt“–ÙŸãø[vó=˘7aÒ¨å$Û)≈ë˘S≠“d‡ßùõI‘Â*fl¿í©õ$ŒÙ‚±ç>?◊+FKÌŒ.8
  233. 1 «òü˛ær—÷Úoìä~yåÊfiSü¡È`?œCÉ5\0úÛ∑†/ÚÔuÕ&N˙íπ}πúå,°G¬•·≮րÜä3°4'P:ß√
  234. —·*≥˛@gd
  235. 5¥Ä?Rú°ªHvÉû‘∏n2åHéßÿˆÉíg~{HΘ˝QdTSó()    Æ∏+Ep3õ%éÓ◊’∂òNÒâClåFÁvAxzE;
  236.             break;
  237.         }
  238.         ++ktp;
  239.     }
  240.  
  241.     if (found) {    /* it exists, just change it then */
  242.         ktp->k_fp = kfunc;
  243.     } else {    /* otherwise we need to add it to the end */
  244.         /* if we run out of binding room, bitch */
  245.         if (ktp >= &keytab[NBINDS]) {
  246.             mlwrite("Binding table FULL!");
  247.             return(FALSE);
  248.         }
  249.  
  250.         ktp->k_code = c;    /* add keycode */
  251.         ktp->k_fp = kfunc;    /* and the function pointer */
  252.         ++ktp;            /* and make sure the next is null */
  253.         ktp->k_code = 0;
  254.         ktp->k_fp = NULL;
  255.     }
  256.     return(TRUE);
  257. }
  258.  
  259. /* unbindkey:    delete a key from the key binding table    */
  260.  
  261. unbindkey(f, n)
  262.  
  263. int f, n;    /* command arguments [IGNORED] */
  264.  
  265. {
  266.     register int c;        /* command key to unbind */
  267.     register char *ptr;    /* ptr to dump out input key string */
  268.     char outseq[80];    /* output buffer for keystroke sequence */
  269.  
  270.     /* prompt the user to type in a key to unbind */
  271.     mlwrite(": unbind-key ");
  272.  
  273.     /* get the command sequence to unbind */
  274.     c = getckey(FALSE);        /* get a command sequence */
  275.  
  276.     /* change it to something we can print as well */
  277.     cmdstr(c, &outseq[0]);
  278.  
  279.     /* and dump it out */
  280.     ptr = &outseq[0];
  281.     while (*ptr)
  282.         (*term.t_putchar)(*ptr++);
  283.  
  284.     /* if it isn't bound, bitch */
  285.     if (unbindchar(c) == FALSE) {
  286.         mlwrite("[Key not bound]");
  287.         return(FALSE);
  288.     }
  289.     return(TRUE);
  290. }
  291.  
  292. unbindchar(c)
  293.  
  294. int c;        /* command key to unbind */
  295.  
  296. {
  297.     register KEYTAB *ktp;    /* pointer into the command table */
  298.     register KEYTAB *sktp;    /* saved pointer into the command table */
  299.     register int found;    /* matched command flag */
  300.  
  301.     /* search the table to see if the key exists */
  302.     ktp = &keytab[0];
  303.     found = FALSE;
  304.     while (ktp->k_fp != NULL) {
  305.         if (ktp->k_code == c) {
  306.             found = TRUE;
  307.             break;
  308.         }
  309.         ++ktp;
  310.     }
  311.  
  312.     /* if it isn't bound, bitch */
  313.     if (!found)
  314.         return(FALSE);
  315.  
  316.     /* save the pointer and scan to the end of the table */
  317.     sktp = ktp;
  318.     while (ktp->k_fp != NULL)
  319.         ++ktp;
  320.     --ktp;        /* backup to the last legit entry */
  321.  
  322.     /* copy the last entry to the current one */
  323.     sktp->k_code = ktp->k_code;
  324.     sktp->k_fp   = ktp->k_fp;
  325.  
  326.     /* null out the last one */
  327.     ktp->k_code = 0;
  328.     ktp->k_fp = NULL;
  329.     return(TRUE);
  330. }
  331.  
  332. desbind(f, n)    /* describe bindings
  333.            bring up a fake buffer and list the key bindings
  334.            into it with view mode            */
  335.  
  336. #if    APROP
  337. {
  338.     buildlist(TRUE, "");
  339. }
  340.  
  341. apro(f, n)    /* Apropos (List functions that match a substring) */
  342.  
  343. {
  344.     char mstring[NSTRING];    /* string to match cmd names to */
  345.     int status;        /* status return */
  346.  
  347.     status = mlreply("Apropos string: ", mstring, NSTRING - 1);
  348.     if (status != TRUE)
  349.         return(status);
  350.  
  351.     return(buildlist(FALSE, mstring));
  352. }
  353.  
  354. buildlist(type, mstring)  /* build a binding list (limited or full) */
  355.  
  356. int type;    /* true = full list,   false = partial list */
  357. char *mstring;    /* match string if a partial list */
  358.  
  359. #endif
  360. {
  361.     register WINDOW *wp;    /* scnaning pointer to windows */
  362.     register KEYTAB *ktp;    /* pointer into the command table */
  363.     register NBIND *nptr;    /* pointer into the name binding table */
  364.     register BUFFER *bp;    /* buffer to put binding list into */
  365.     char *strp;        /* pointer int string to send */
  366.     int cpos;        /* current position to use in outseq */
  367.     char outseq[80];    /* output buffer for keystroke sequence */
  368.  
  369.     /* split the current window to make room for the binding list */
  370.     if (splitwind(FALSE, 1) == FALSE)
  371.             return(FALSE);
  372.  
  373.     /* and get a buffer for it */
  374.     bp = bfind("Binding list", TRUE, 0);
  375.     if (bp == NULL || bclear(bp) == FALSE) {
  376.         mlwrite("Can not display binding list");
  377.         return(FALSE);
  378.     }
  379.  
  380.     /* let us know this is in progress */
  381.     mlwrite("[Building binding list]");
  382.  
  383.     /* disconect the current buffer */
  384.         if (--curbp->b_nwnd == 0) {             /* Last use.            */
  385.                 curbp->b_dotp  = curwp->w_dotp;
  386.                 curbp->b_doto  = curwp->w_doto;
  387.                 curbp->b_markp = curwp->w_markp;
  388.                 curbp->b_marko = curwp->w_marko;
  389.         }
  390.  
  391.     /* connect the current window to this buffer */
  392.     curbp = bp;    /* make this buffer current in current window */
  393.     bp->b_mode = 0;        /* no modes active in binding list */
  394.     bp->b_nwnd++;        /* mark us as more in use */
  395.     wp = curwp;
  396.     wp->w_bufp = bp;
  397.     wp->w_linep = bp->b_linep;
  398.     wp->w_flag = WFHARD|WFFORCE;
  399.     wp->w_dotp = bp->b_dotp;
  400.     wp->w_doto = bp->b_doto;
  401.     wp->w_markp = NULL;
  402.     wp->w_marko = 0;
  403.  
  404.     /* build the contents of this window, inserting it line by line */
  405.     nptr = &names[0];
  406.     while (nptr->n_func != NULL) {
  407.  
  408.         /* add in the command name */
  409.         strcpy(outseq, nptr->n_name);
  410.         cpos = strlen(outseq);
  411.         
  412. #if    APROP
  413.         /* if we are executing an apropos command..... */
  414.         if (type == FALSE &&
  415.             /* and current string doesn't include the search string */
  416.             strinc(outseq, mstring) == FALSE)
  417.             goto fail;
  418. #endif
  419.         /* search down any keys bound to this */
  420.         ktp = &keytab[0];
  421.         while (ktp->k_fp != NULL) {
  422.             if (ktp->k_fp == nptr->n_func) {
  423.                 /* padd out some spaces */
  424.                 while (cpos < 25)
  425.                     outseq[cpos++] = ' ';
  426.  
  427.                 /* add in the command sequence */
  428.                 cmdstr(ktp->k_code, &outseq[cpos]);
  429.                 while (outseq[c¸Ê¨ä€¨ä€ˇ˛î¸ÊTEXTMARC:99BSEARCH.C2nÀÑB˝∂,Ó˛~¨ä€¨ä€ˇ˛î˛~TEXTMARC87M:BSPAWN.CnÀ@ÑB˝∂$Ó˝≤¨ä€¨ä€ˇ˛î˝≤TEXTMARC8;BTCAP.C
  430. pÀ@ÑB˝∂-ӽܨ䀠¨ä€!ˇ˛î˝ÜTEXTMARC21˜<BTERMIO.CenÀ@@ÑB˝∂ Ó˝¨ä€#¨ä€$ˇ˛î˝TEXTMARC´=BTIPC.C*nÀ@ÄÑB˝∂+Ó˝Æ¨ä€'¨ä€(ˇ˛î˝ÆTEXTMARCI>BVMSVT.CnÀ@¿ÑB˝∂#Ó¸“¨ä€*¨ä€*ˇ˛î¸“TEXTMARC
  431. ?BVT52.CbpÀ@ÑB˝∂0Ó¸⁄¨ä€0¨ä€1ˇ˛î¸⁄TEXTMARC@?W@BWINDOW.C    nÀ@@ÑB˝∂%Ó¨ä€7¨ä€8ˇ˛î¸‚TEXTMARC@?–ABWORD.Cr Àtch À
  432. Finder 1.0
  433. ∏t´~Àú»ÅˇÊ{Ó¸ÍúÀÃúÀÃġ˝Úˇ⁄>˙¢ˇ¯ˇ¸ÍMT Sourcecode 26/EMACS <ÀÜ^    ıˇÚ¸N
  434. MockWritefÀ
  435. Àw#ô!,À$•V≠•¨ˇ¶¨≠ˇV≠ˇˇÀAPPLfnÀÑB˝∂!Ó¸‚¨ä⁄~¨ä⁄~ˇ˛î˝TEXTMARC†BANSI.Ci À    /* À
  436. ˇ‰ˇÇÑÀw#ôÄÀw#ôT;ÀHRC9mpÀ\»ÅġÊ8Ó˝∂úÖˆJ¨äflFˇ˛îÄ˝
  437. ÓÉq>[ˇô˝∂    MTP-8-019ÀÓÉq>)S∑ÀAPPL    2À˝förÀˇˇ€ᡡ—ˇ—ˇ—ˇÚ¸. ÀAPPLsÀAPPL/Àw#ôËÀPREShÆÀFED+Fedit Plus 1.1DMOV
  438. Font/DA MoverMZT1 MacZap Tools
  439. FKEYFONT-FKEY-DA Sampler&ScavDisk First Aid.FAFOFast Formatter 2.11HSDVVerify ÀTEXTedit.resinÀ@ÑB˝∂'Ó¸Ó¨ä⁄Ǩä⁄ɡ˛î¸ÓTEXTMARC0.    BBASIC.CzÀ‚‚IJ     Ah¢AmF¸    Ü^À
  440. Z8ÀMACAICN#Ä1hFREFÄÅÇÉÀ
  441. Ã⁄ÀPRES IMAGEWRITERÀTEXTh Àan p2ÀˇäôΔ≠ˇˇΩܡˇˇˇˇÚ˚ÊnÀ
  442. ƺ  443. ÆÀã†0ˇˇˇ˚About the Finder…- Alarm ClockChooserControl Panel
  444. MockWrite
  445. ReadMacWriteSleepTime Transfer...    nÀÄÑB˝∂ Ó˝¨ä⁄à¨ä⁄⡲îTEXTMARC<;V B˚ÓBIND.CÆpÀ¿ÑB˝∂,Ó¸˛¨ä⁄é¨ä⁄èˇ˛î¸˛TEXTMARC@>s!BBUFFER.CnÀÑB˝∂)Ó˝¨ä⁄í¨ä⁄ìˇ˛î˝TEXTMARCb"BCRYPT.CnÀ@ÑB˝∂#Ӳܨä⁄ï¨ä⁄ïˇ˛î˛ÜTEXTMARC Ó#BDG10.C‚À
  446. ÓÉq>À
  447. À¸ˇ¿Üˇ¿Öˇ¿áá¿Äó–ÄøÄì‡ÄÉ¿ÄɡÉ?¯  /ä(è"(ÅA(ÅÄø(ÅA/Å" ! Q â!¸ âÜ QÖ !áÅ/ÅÄë(ÅÄø(ÅÄê(ÅÄÄ(ÅÄÄ/ŎĠ?ˇ¸˛ˇ‡ˇˇ‡ˇüˇ¯ˇøè¯ˇˇè¯ˇøáˇüɇˇáÅ¿ˇáø¯ø¸ø˛øˇ>øˇ?øˇˇˇøˇ?øˇ>øˇøˇøˇøˇ¸øˇ˛øˇˇøˇˇõøˇˇøøˇˇˇøˇˇøøˇˇò?ˇˇÄ?ˇˇÄ?ˇ?ˇ4ÀPIT ICN#h    Rh™FREF
  448. 7QkcÀGenerator Disk IIJÀ\»Åǡ˛Ì
  449. '΂úÖˆJ¨ä—mˇ˛ÿùX>1ΩˇÙ ΂ÎÓÀw#ôfxÀMARC=ÏÀ∫∫„rîÄ⁄STR :FOBJFBNDLRICN#^FREFÇPIT ¶APPL≤ˇˇ˚fpˇ¶ˇˇ$ˇΔhˇˇ$?ˇ™    Rˇˇ$C¸éh™ˇˇ$Gˇ“
  450. ˇˇ$Kˇ÷7Qˇˇ$Vˇ¬kcˇˇ$a˝éˇˇ$l˝ûˇˇ$∂¸˙UntitlednvÀaÉġûGÓ¸fi¨ä€U¨ä€Üˇ˛î∏t´ˇ¯ˇôΔ$¸fiB¸Íemacs source ƒ*À
  451. YˇmYˇm2Àô¨uºˇ[Y[ˇÚ˝ÇuÀ
  452. U≠eª